package com.example.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class DirectRabbitmqConfig {
    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue directQueue(){
        return new Queue("directQueue",true);
    }

    /**
     * 声明直连型交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("directExchange",true,false);
    }

    /**
     * 将交换机和队列绑定，并设置匹配键directQueueTest1
     * @return
     */
    @Bean
    public Binding bindingDirect(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("directQueueTest1");
    }
}
